<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_IFRAME_VIEW . 'subjectPrintPreview.html'));
	$CID 	= _GET('id');
	$semesterLinker = $DSC->getSemesterLinker($CID);
	
	if ( !empty($semesterLinker) ) {
		$TEMP->set_block('handle',  'semester', 'semesterRow');
		foreach($semesterLinker as $semesterLinkerField => $semesterLinkerValue) {
			
			$semDesc 	 = $semesterLinkerValue['sem_desc'];
			$semLinkerID = $semesterLinkerValue['sem_linker_idPK'];
			
			$semNote	 = (!empty($semesterLinkerValue['note'])) ? '*NOTE: ' . $semesterLinkerValue['note'] : '';
			
			$subjectListing = '';
			
			$subjectListingSemLinker = $DSC->getSubjectListingSemLinker($semLinkerID, $activeYear);
			
			if( !empty($subjectListingSemLinker) ) {
				$totalHRSTotal 	= 0;
				$totalUnits 	= 0;
				foreach($subjectListingSemLinker as $subjectListingSemLinkerValue) {
					
					$total_units 			= $subjectListingSemLinkerValue['total_units'];
					$total_units_parenthesis = ($total_units < 0) ? '(' . abs($total_units) . ')' : $total_units;
					
					$coChar  = (!empty($subjectListingSemLinkerValue['co_req'])) ? $DSC->getReqSubjectID($subjectListingSemLinkerValue['co_req']) : 'None';
					$preChar = (!empty($subjectListingSemLinkerValue['pre_req'])) ? $DSC->getReqSubjectID($subjectListingSemLinkerValue['pre_req']) : 'None';
					
					$totalHRS = $subjectListingSemLinkerValue['total_hrs'];
					
					$subjDesc = $subjectListingSemLinkerValue['subj_desc'];
							
					$lastInsert = ($subjectListingSemLinkerValue['subj_idPK'] == $LASTID) ? 'active-light' : '';
							
					$subjectListing .= '<tr align="center" class="hover-light ' . $lastInsert . '">
											<td class="subject-td-bot" align="left">' . $subjDesc . '</td>
											<td class="subject-td-bot">' . $subjectListingSemLinkerValue['subj_code'] 	. '</td>
											<td class="subject-td-bot">' . $total_units_parenthesis 	. '</td>
											<td class="subject-td-bot">' . $subjectListingSemLinkerValue['lec_units'] 	. '</td>
											<td class="subject-td-bot">' . $subjectListingSemLinkerValue['lab_units'] 	. '</td>
											<td class="subject-td-bot">' . $subjectListingSemLinkerValue['lec_lab_units'] . '</td>
											<td class="subject-td-bot">' . $coChar 		. '</td>
											<td class="subject-td-bot">' . $preChar 	. '</td>
											<td class="subject-td-bot">' . $totalHRS 	. '</td>
										</tr>';
					if ($total_units > 0) {
						$totalUnits = $totalUnits + $total_units;
					}
					$totalHRSTotal = $totalHRSTotal + $totalHRS;
				}
				#TOTAL
				$subjectListing .= '<tr align="center">
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"><strong>' . $totalUnits . '</strong></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"></td>
										<td class="subject-td-bot"><strong>' . $totalHRSTotal . '</strong></td>
									</tr>';
				
			}
			$TEMP->set_var(array('sem_desc' 			=> '<div class="subj-year-semester-value">' . $semDesc . '</div>',
								 'sem_linker_id' 		=> $semLinkerID,
								 'sem_note'				=> $semNote,
								 'subject_listing' 		=> $subjectListing));
			$TEMP->parse('semesterRow', 'semester', true);
		}
	}
	else {
		$TEMP->set_var(array('sem_desc' 			=> '',
							 'add_subject_button' 	=> '',
							 'sem_linker_id' 		=> '',
							 'subject_listing'		=> ''));
	}
	
	##################### CHECKLIST HEADER #####################
	
		$getCourse 	  = $DSC->getCourse($CID);
		$courseHeader = $DSC->getCourseHeader($getCourse['course_idPK']);
		$course_label	= $getCourse['course_desc'] . ' (' . $getCourse['course_code'] . ')';
	
	##################### CHECKLIST HEADER #####################
	
	$TEMP->set_var(array('search' 			=> $search,
						 'dept_course'		=> $courseHeader['dept_desc'],
						 'course_desc'		=> $course_label,
						 'course_id'		=> $CID,
						 'based'			=> $courseHeader['head_based'],
						 'year'				=> $courseHeader['head_year']
						));
?>